﻿
@{
    ViewBag.MainMenu = "Settings";
    ViewBag.LeftMenu = "AutoReply";

    ViewBag.Title = "自动回复";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script language="javascript">

    $(document).ready(function ()
    {
        loadData();
    });

    function loadData()
    {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/Settings/GetAutoReplyOnMessage",
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR)
            {
                layer.close(loadLayerIndex);
                if (data.Success)
                {
                    // __setMaterial(data.Data);
                    __setMaterial(data.Data.Type, data.Data.Content, data.Data.MaterialId);
                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function save()
    {
        if (__validateMaterialSelect() == false)
            return;

        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        var args = new Object();
        args.Type = __materialType;
        args.Content = __getMaterialText();
        if (__materialImage != undefined && __materialImage != null)
        {
            args.Name = __materialImage.Name;
            args.Url = __materialImage.Url;
            args.MediaId = __materialImage.MediaId;
        }
        args.MaterialId = __materialSelect_materialId;

        $.ajax({
            url: "/Api/Settings/SaveAutoReplyOnMessage",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                // alert(data);
                layer.close(loadLayerIndex);
                if (data.Success)
                {
                    layerAlert("自动回复已保存，您的设置将在几分钟之内生效。");
                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

</script>

<div id="divContentTips">
    公众号收到会员的消息后，首先在关键词自动回复中查找匹配的回复内容，如果没有，则统一回复此处配置的消息自动回复内容。
</div>

<div style=" margin-top:20px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="td_ContentTab" style="width:200px;"><a href="/Settings/AutoReplyOnSubscribe" class="a_black_16">被添加自动回复</a></td>
            <td class="td_ContentTab_active" style="width:200px;">消息自动回复</td>
            <td class="td_ContentTab" style="width:200px;"><a href="/Settings/AutoReplyOnKeywords" class="a_black_16">关键词自动回复</a></td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="4" bgcolor="#EEEEEE" height="2"></td>
        </tr>
    </table>
</div>

<div style="margin-left:20px; margin-right:20px;">

    @Helpers.MaterialSelect(true,true,false)

    <div style=" margin-top:25px;">
        <input name="btnSave" type="button" class="btn_blue" id="btnSave" value="保存" onclick="save()" />
    </div>

</div>
